<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/25
 * 多任务
 */
namespace app\job\controller;

use think\Exception;
use think\Queue;

class JobMultiTest{
    public function MultiJob(){
        $type = $_GET['type'] ? $_GET['type'] : 'taskB';
        switch($type){
            case 'taskA':
                $jobHandlerClassName = 'app\job\MultiTask@task1'; //消息名称 消费者名称
                $jonData             = ['a' => 1];
                $jobQueueName        = 'multiTaskJobQueue';
                break;
            case 'taskB':
                $jobHandlerClassName = 'app\job\MultiTask@task2'; //消息名称 消费者名称
                $jonData             = ['b' => 2];
                $jobQueueName        = 'multiTaskJobQueue';
                break;
            default:
                break;
        }
        $isPushed = Queue::push($jobHandlerClassName, $jonData, $jobQueueName);
        if($isPushed !== false){
            echo("the $type of MultiTask Job has been Pushed to " . $jobQueueName . "<br>");
        }else{
            throw new Exception("push a new $type of MultiTask Job Failed!");
        }
    }
}
